<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>组织管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
   <div class="ccpui-sortFunction">
       <ul class="orgSortInfo">
       </ul>

        <div class="orgSortOpt">
           <button class="layui-btn topSort">顶部</button>
           <button class="layui-btn upSort">上移</button>
           <button class="layui-btn downSort">下移</button>
           <button class="layui-btn bottomSort">底部</button>
        </div>
       <div style="width: 100%;float: left;margin: 10px;text-align: center">
           <button class="layui-btn saveSort">保存</button>
           <button class="layui-btn cancelSort layui-btn-danger">取消</button>
       </div>
   </div>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter', 'commons', 'form', 'jquery', 'layer'], function () {
        var layer = layui.layer,
        commons = layui.commons, $=layui.jquery,
        setter = layui.setter;

        var orgid = '${orgId}';
        // 获取本级组织data
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: serverPath.systemPath + setter.sysLinkPath+ "sysOrg/listForSort",
            data: {
                orgId:orgid
            },
            success: function (data) {
                var result = data.data;
                if(result.length>0){
                    for(var i = 0; i<result.length;i++){
                        $('.orgSortInfo').append('<li class="" value="'+result[i].orgId+'">'+result[i].name+'</li>')
                    }
                }
            }
        });
        
        $('.saveSort').click(function () {
            var orgIds = [];
            $('.orgSortInfo li').each(function () {
                orgIds.push($(this).attr('value'));
            });
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: serverPath.systemPath + setter.sysLinkPath+ "sysOrg/sort",
                data: {
                    orgIds:orgIds.join(',')
                },
                success: function (data) {
                    if (commons._filterRecord(data)) {
                        layer.alert(data.msg, function(index) {
                            layer.close(index);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            $('#btn-refresh', window.parent.document).click();
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            });
        });
        $(".cancelSort").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
            return false
        });
        $(document).on('click','.orgSortInfo  li',function () {
            $('.orgSortInfo  li').removeClass('selectIndex');
            $(this).addClass('selectIndex');
        });
        $(document).on('click','.topSort',function () {
            $('.orgSortInfo li:first-child').before($('.selectIndex'))
        });
        $(document).on('click','.bottomSort',function () {
            $('.orgSortInfo li:last-child').after($('.selectIndex'))
        });
        $(document).on('click','.upSort',function () {
            var index = $('.selectIndex').index() - 1;
            if(index > -1){
                $('.orgSortInfo li').eq(index).before($('.selectIndex'))
            }
        });
        $(document).on('click','.downSort',function () {
            var index = $('.selectIndex').index() + 1;
            $('.orgSortInfo li').eq(index).after($('.selectIndex'))
        });


    });
</script>
</body>
</html>